package cn.ghf.basic.service.impl;


import cn.ghf.basic.mapper.BaseMapper;
import cn.ghf.basic.query.BaseQuery;
import cn.ghf.basic.service.IBaseService;
import cn.ghf.basic.util.PageList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class BaseServiceImpl<T> implements IBaseService<T> {

    @Autowired
    private BaseMapper<T> mapper;

    @Override
    public void add(T t) {
        mapper.add(t);
    }

    @Override
    public void update(T t) {
        mapper.update(t);
    }

    @Override
    public void delete(Long id) {
        mapper.delete(id);
    }

    @Override
    public T loadById(Long id) {
        return mapper.loadById(id);
    }

    @Override
    public List<T> loadAll() {
        return mapper.loadAll();
    }

    @Override
    public PageList<T> queryData(BaseQuery query) {
        List<T> t = mapper.queryData(query);
        Long count = mapper.queryCount(query);
        return new PageList<T>(count,t);
    }

    @Override
    public void patchDelete(Long[] ids) {
        mapper.patchDel(ids);
    }
}
